(function() {
    'use strict';

    /**
     * @ngdoc directive
     * @name webApp.directive:uploader
     * @description
     * # uploader
     */
    angular.module('webApp')

    .run(["$templateCache", "dataService", function($templateCache, dataService) {
            var tplName = "views/directives.wxapplet.html";
            dataService.tpl(tplName).then(function(html) {
                $templateCache.put(tplName, html);
            });
        }])
        .directive('wxapplet', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    scope: {
                        callback: "&",
                        wxgzhappid: "=",
                        ngclass: "@",
                        sbutype: "@"
                    },
                    template: '<span><a href="" class="{{ngclass}}" ng-click="initData()" >选择小程序</a></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.initData = function() {
                                showPop();
                            }
                            $scope.save = function() {
                                $scope.applet.wxappid = $scope.wxappid;
                                $scope.applet.wxappname = $scope.storeary.nick_name;
                                if ($scope.applet.radio == 'wximg' && !$scope.applet.wximg) {
                                    helper.myAlert("图片没有选择！");
                                    return;
                                }
                                $scope.callback({
                                    attach: $scope.applet
                                });
                                rmAlert();
                            }

                            $scope.addimgurl = function(url) {
                                if (url) {
                                    $scope.applet.wximg = url;
                                }
                                // console.error("url",url);
                            }
                            $scope.wxaacallback = function(aap_id) {
                                $scope.applet.wxappid = aap_id;
                                if ($scope.storeary) {
                                    $scope.applet.wxappname = $scope.storeary.nick_name;
                                }
                                // console.log($scope.applet);
                            }

                            $scope.savepath = function(path) {
                                if (path) {
                                    $scope.applet.path = path;
                                    // console.log($scope.applet);
                                }
                            }

                            function showPop() {
                                $scope.applet = {
                                    "nick_name": "",
                                    "radio": 'title',
                                    title: "",
                                    img: "",
                                    wxappid: ""
                                };
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>{{"小程序"|translate}}</span>',
                                    body: $templateCache.get("views/directives.wxapplet.html"),
                                    okBtn: 'ok',
                                    hasfoot: false,
                                    closeBtn: true,
                                    transition: true,
                                    width: '400px',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {
                                        // console.error("e",e);
                                        // rmAlert();
                                    },
                                });
                            }
                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])

    .directive('wxinfo', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    require: 'ngModel',
                    scope: {
                        ngModel: '=',
                        stye: "@",
                        type: "@",
                        isCb: "@",
                        userid: "@",
                        cb: "&",
                        isName: '@',
                        isUrl: '@'
                    },
                    template: '<span ng-show="!isCb"><a href="{{iamurl}}" target="_black"><img ng-src="{{iamurl}}" width="60px" ng-show="!isUrl"> </a> <br ng-show="!isUrl"/><span ng-show="!isName">{{name}}</span> </span> ',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            // console.error("ngModel",$scope.ngModel);
                            $scope.initData = function() {
                                if ($scope.stye) {
                                    var query = {
                                        query: {
                                            member_id: $scope.ngModel
                                        }
                                    };
                                    dataService.memberGet(query).then(function(list) {
                                        if (list.wx_members.length > 0) {
                                            $scope.iamurl = list.wx_members[0].avatar_url;
                                            $scope.name = list.wx_members[0].nick_name;
                                            if ($scope.isCb) {
                                                $scope.cb({
                                                    "iamurl": $scope.iamurl,
                                                    "nick": $scope.name
                                                });
                                            }
                                        }
                                    });
                                } else {
                                    var query = {};
                                    if ($scope.userid) {
                                        query.user_id = $scope.ngModel;
                                    } else {
                                        query.open_id = $scope.ngModel;
                                    }
                                    var api = $scope.type ? "buyerbasicinfoGet" : "basicinfoGet";
                                    dataService[api](query).then(function(list) {
                                        if (list) {
                                            $scope.iamurl = list.avatar_url;
                                            $scope.name = list.nick_name;
                                        }
                                    });
                                }
                            }
                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {
                        //初始化
                        ctrl.$render = function() {
                            scope.initData(ctrl.$viewValue);
                        };
                    }
                }
            }
        ])
        .directive('fxQrcode', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    // require: 'ngModel',
                    scope: {
                        fxid: "=",
                    },
                    template: '<span><button ng-click="show();" class="sui-btn btn-success">{{title}}</button></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.title = $scope.title ? $scope.title : "商品二维码"
                            $scope.init = function() {
                                $scope.stype = '';
                                $scope.show();
                            }
                            $scope.itemdata = function(item) {
                                if (item) {
                                    $timeout(function() {
                                        $scope.stype = "ITEM" + item.item_id + "FXID" + $scope.fxid;
                                    });
                                }
                            }
                            $scope.show = function() {
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>小程序二维码，请使用微信扫描</span>',
                                    body: '<div><div class="sui-form sui-form"><form class="sui-form" style="margin:0px;"><div>选择商品:<choice-item item-check="itemdata(items)" is-chose-item="1" ></choice-item></div>  <br/><br/><div  ng-if="stype"><wx-qrcode stype="stype" id="itemid" storeid="1" ></wx-qrcode> </div></form></div></div>',
                                    // okBtn: '{{"ok" | translate}}',
                                    closeBtn: true,
                                    hasfoot: false,
                                    transition: true,
                                    width: 'small',
                                    // height: '200',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {

                                    },
                                });
                            }


                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        //<div ng-show="path">选择路径:<page-path ng-model="pagePath" ></page-path></div> 
        .directive('wxPathQrcode', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    // require: 'ngModel',
                    scope: {
                        // stype: "=",
                        id: "=",
                    },
                    template: '<span><button ng-click="show();" class="sui-btn btn-success">{{title}}</button></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.title = $scope.title ? $scope.title : "二维码"
                            $scope.init = function() {
                                $scope.stype = '';
                                $scope.show();
                            }
                            $scope.backcalldata = function(data) {
                                if (data) {
                                    $timeout(function() {
                                        $scope.pagePath = data + "?food_id=" + $scope.id + "&store_id=" + $rootScope.store_id;
                                    });
                                }
                            }

                            $scope.getWxqr = function() {
                                var query = {
                                    desk_id: $scope.id,
                                    appid: $scope.wxappid,
                                    path: $scope.pagePath,
                                };
                                dataService.deskQrcode(query).then(function(list) {
                                    if (list.imgUrl) {
                                        $scope.qrimage = "data:image/png;base64," + list.imgUrl;
                                    } else {
                                        helper.myAlert("erro " + list.Msg);
                                    }
                                });
                            }
                            $scope.show = function() {
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>小程序二维码，请使用微信扫描</span>',
                                    body: '<div><div class="sui-form sui-form"><form class="sui-form" style="margin:0px;"><div >选择 路径：<page-path ng-model="pagePath" backcall="backcalldata(data)" ></page-path></div><br/><div>选择小程序:<wx-app-list ng-model="wxappid" dft="1" ary="storeary" storedata="1" > </wx-app-list></div><br/><div  ng-if="pagePath"><button class="sui-btn btn-success " ng-click="getWxqr()">生成二维码</button><img  ng-src="{{qrimage}}" width="240px"> </div></form></div></div>',
                                    // body: '<div><div class="sui-form sui-form"><form class="sui-form" style="margin:0px;"><div >选择路径:<page-path ng-model="pagePath" backcall="backcalldata(data)" ></page-path></div>  <br/><br/><div  ng-if="pagePath"><wx-qrcode stype="stype" id="id" storeid="1"  xpath="{{pagePath}}" type="1" ></wx-qrcode> </div></form></div></div>',
                                    closeBtn: true,
                                    hasfoot: false,
                                    transition: true,
                                    width: 'small',
                                    // height: '200',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {

                                    },
                                });
                            }


                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        .run([
            "$templateCache",
            "dataService",
            function($templateCache, dataService) {
                var tplName = "views/directives.wxqrcode.html";
                dataService.tpl(tplName).then(function(html) {
                    $templateCache.put(tplName, html);
                });
            }
        ])
        .directive('wxQrcode', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    // require: 'ngModel',
                    scope: {
                        // wxappid: "=",
                        stype: "=",
                        itempath: "@",
                        xpath: "@",
                        title: "@",
                        storeid: "@",
                        type: "@",
                        spath: "@",
                        id: "="
                    },
                    template: '<span><button ng-click="show();" class="sui-btn btn-success">{{title}}</button></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.title = $scope.title ? $scope.title : "二维码"
                            $scope.$watch('storeary', function(newValue, oldValue, scope) {
                                if (newValue) {
                                    $scope.store_id = newValue.store_id;
                                    $scope.initData();
                                }
                            }, true);

                            $scope.init = function() {
                                $scope.store_id = $rootScope.store_id;
                                $scope.initData().then($scope.show);
                            }

                            $scope.initData = function() {
                                var scence = '';
                                if (!$scope.storeid) {
                                    scence = "S" + $scope.store_id + "";
                                }
                                if ($scope.stype) {
                                    scence += $scope.stype;
                                }

                                if ($scope.id) {
                                    scence += $scope.id;
                                }

                                if ($scope.itempath) {
                                    $scope.itempath = "pages/goods/detail/index?item_id=" + $scope.id;
                                    // $scope.path = "pages/goods/detail/index?item_id=" + $scope.id;
                                }

                                if ($scope.xpath) {
                                    $scope.path = $scope.xpath;
                                }
                                if ($scope.spath && $scope.wxappid == 'wxecb076c64291682c') {
                                    $scope.path = "pages/JR/order/index";
                                }
                                $scope.path = $scope.path ? $scope.path : "pages/index/index";
                                $scope.scence = scence;
                                return $scope.getimg();
                            }

                            $scope.getimg = function() {
                                $scope.qrimage = "";
                                if ($scope.type) {
                                    return $scope.getimgone();
                                } else {
                                    return $scope.getimgtwo();
                                }
                            }

                            $scope.getimgone = function() {
                                return dataService.acodeGet($scope.wxappid, $scope.path, true).then(function(qrimage) {
                                    if (qrimage) {
                                        return $scope.qrimage = "data:image/png;base64," + qrimage;
                                    } else {
                                        helper.message("路径不正确");
                                        return false;
                                    }
                                });
                            }
                            $scope.getimgtwo = function() {
                                    return dataService.acodeunlimitGet($scope.wxappid, $scope.scence, true, $scope.path).then(function(qrimage) {
                                        console.error("qrimage", qrimage);
                                        if (qrimage) {
                                            return $scope.qrimage = "data:image/png;base64," + qrimage;
                                        } else {
                                            helper.message("路径不正确");
                                            return false;
                                        }
                                    });
                                }
                                // $templateCache.get("views/directives.wechatlogistic.html"),
                            $scope.show = function() {
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>小程序二维码，请使用微信扫描</span>',
                                    body: $templateCache.get("views/directives.wxqrcode.html"),
                                    // okBtn: '{{"ok" | translate}}',
                                    closeBtn: true,
                                    hasfoot: false,
                                    transition: true,
                                    width: 'small',
                                    // height: '200',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {

                                    },
                                });
                            }


                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        .directive('storeQrcode', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    scope: {
                        wxappid: "=",
                        title: "@",
                    },
                    template: '<span><button ng-click="init();" class="sui-btn btn-success">{{title}}</button></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.title = $scope.title ? $scope.title : "二维码";
                            $scope.init = function() {
                                    wxappQrcode().then(show);
                                }
                                //小程序二维码
                            function wxappQrcode() {
                                $scope.path = $scope.path ? $scope.path : "pages/index/index";
                                $scope.showpath = $scope.path + "?store_id=" + $rootScope.store_id
                                return dataService.acodeunlimitGet($scope.wxappid, "S" + $rootScope.store_id, true, $scope.path).then(function(r) {
                                    return $scope.qrimage = "data:image/png;base64," + r;
                                });
                            }

                            function show() {
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>小程序二维码，请使用微信扫描</span>',
                                    body: '<div style="text-align:center;"> <img src="{{qrimage}}"  width="240"/><div><a-url setback="savepath(path)"></a-url><br/><input ng-model="showpath" style="width:50%;"></div></div>',
                                    // okBtn: '{{"ok" | translate}}',
                                    closeBtn: true,
                                    hasfoot: false,
                                    transition: true,
                                    width: 'small',
                                    // height: '200',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {

                                    },
                                });
                            }
                            //
                            $scope.savepath = function(path) {
                                if (path) {
                                    if (path.indexOf('?') > 0) {
                                        helper.myAlert("此链接不能生成二维码！");
                                        return false
                                    } else {
                                        $scope.path = path.substr(1);
                                        wxappQrcode();
                                    }

                                }
                            }

                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        .directive('getMember', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    // require: 'ngModel',
                    scope: {
                        memberid: '=',
                        stye: "@",
                    },
                    template: '<span ng-show="!stye"> <a href="{{iamurl}}" target="_black"  ><img ng-src="{{iamurl}}" width="60px"> </a></span> <span ng-show="stye">{{name}}</soan>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.initData = function() {
                                // console.error("$scope.memberid",$scope.memberid);
                                var query = {
                                    query: {
                                        member_id: $scope.memberid
                                    }
                                };
                                dataService.memberGet(query).then(function(list) {
                                    if (list.wx_members.length > 0) {
                                        $scope.iamurl = list.wx_members[0].avatar_url;
                                        $scope.name = list.wx_members[0].nick_name;
                                    }
                                });
                            }
                            $scope.initData();
                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        .run(["$templateCache", "dataService", function($templateCache, dataService) {
            var tplName = "views/directives.wxtitle.html";
            dataService.tpl(tplName).then(function(html) {
                $templateCache.put(tplName, html);
            });
        }])
        .directive('wxTitle', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    require: 'ngModel',
                    scope: {
                        ngModel: '=',
                        wxappid: '=',
                    },
                    template: '<span><a href="" ng-click="initData()" class="sui-btn  btn-xlarge btn-primary" >标题、封面</a></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.initData = function() {
                                showPop();
                            }
                            $scope.save = function() {
                                // $scope.applet.wxappid = $scope.wxappid;
                                // $scope.applet.wxappname = $scope.storeary.nick_name;
                                // if ($scope.applet.radio == 'wximg' && !$scope.applet.wximg) {
                                //     helper.myAlert("图片没有选择！");
                                //     return;
                                // }
                                // $scope.callback({
                                //     attach: $scope.applet
                                // });
                                // rmAlert();
                            }

                            $scope.addimgurl = function(attach) {
                                $timeout(function() {
                                    $scope.ngModel.thumb_url = attach.url;
                                    $scope.ngModel.thumb_media_id = attach.media_id;
                                });
                            }

                            function showPop() {
                                $scope.applet = {
                                    "nick_name": "",
                                    "radio": 'title',
                                    title: "",
                                    img: "",
                                    wxappid: ""
                                };
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>{{"标题、封面"|translate}}</span>',
                                    body: $templateCache.get("views/directives.wxtitle.html"),
                                    okBtn: 'ok',
                                    // hasfoot: false,
                                    closeBtn: true,
                                    transition: true,
                                    width: '600px',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {
                                        $scope.save();
                                        // console.error("e",e);
                                        // rmAlert();
                                    },
                                });
                            }
                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        .run(["$templateCache", "dataService", function($templateCache, dataService) {
            var tplName = "views/directives.wxmaterial.html";
            dataService.tpl(tplName).then(function(html) {
                $templateCache.put(tplName, html);
            });
        }])
        .directive('wxMaterial', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    // require: 'ngModel',
                    scope: {
                        balck: '&'
                    },
                    template: '<span><a href="" ng-click="initData()" class="sui-btn btn-primary" >选择文章</a></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.initData = function() {
                                // $scope.getlist().then();
                                showPop();
                            }
                            $scope.chengGhz = function(app_id) {
                                if (app_id) {
                                    $scope.wxappid = app_id;
                                    $scope.getlist(1);
                                }

                            }
                            $scope.isChecked = function($event, list) {
                                var status = $event.currentTarget.checked;
                                if (status) {
                                    $scope.item = list;
                                }
                            }
                            $scope.getlist = function(pageNo, offset) {
                                if ($scope.wxappid) {
                                    $scope.address = {
                                        "type": 'news',
                                        "offset": (pageNo - 1) * 10,
                                        "count": $scope.pageSize ? $scope.pageSize : 10,
                                    }
                                    return dataService.wxproxy($scope.wxappid, 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=TOKEN', 'POST', $scope.address).then(function(result) {
                                        $scope.itemlist = result.item;
                                        $scope.total_count = result.total_count;
                                        $scope.item_count = result.item_count;
                                        return $scope.itemlist;
                                    });
                                }

                            }

                            //保存
                            $scope.callback = function() {
                                if ($scope.balck) {
                                    $scope.balck({
                                        "content": $scope.item
                                    })
                                }
                            }

                            function showPop() {
                                $scope.applet = {
                                    "nick_name": "",
                                    "radio": 'title',
                                    title: "",
                                    img: "",
                                    wxappid: ""
                                };
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>{{"文章选择"|translate}}</span>',
                                    body: $templateCache.get("views/directives.wxmaterial.html"),
                                    okBtn: 'ok',
                                    // hasfoot: false,
                                    closeBtn: true,
                                    transition: true,
                                    width: 'large',
                                    height: 400,
                                    // height: '500 px',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {
                                        $scope.callback();
                                        // console.error("e",e);
                                        // rmAlert();
                                    },
                                });
                            }
                        }
                    ],

                    link: function(scope, element, attrs, ctrl) {

                    }
                }
            }
        ])
        .run([
            "$templateCache",
            "dataService",
            function($templateCache, dataService) {
                var tplName = "views/directives.paymentqrcode.html";
                dataService.tpl(tplName).then(function(html) {
                    $templateCache.put(tplName, html);
                });
            }
        ])
        .directive('paymentQrcode', ['dataService', '$compile', 'helper', '$timeout', 'dhfprinterService',
            function(dataService, $compile, helper, $timeout, dhfprinterService) {
                return {
                    restrict: 'EA',
                    // require: 'ngModel',
                    scope: {
                        // wxappid: "=",
                        title: "@",
                        storeid: "@",
                        id: "=",
                        orderData: "="
                    },
                    template: '<span><button ng-click="show();" class="sui-btn btn-success">{{title}}</button></span>',
                    controller: ['$templateCache', '$rootScope', '$scope', '$state',
                        function($templateCache, $rootScope, $scope, $state) {
                            $scope.title = $scope.title ? $scope.title : "补缺支付单"
                            $scope.$watch('storeary', function(newValue, oldValue, scope) {
                                if (newValue) {
                                    $scope.store_id = newValue.store_id;
                                    $scope.initData();
                                }
                            }, true);

                            $scope.init = function() {
                                $scope.store_id = $rootScope.store_id;
                                $scope.initData().then($scope.show);
                            }

                            $scope.initData = function() {
                                var scence = '';
                                if (!$scope.storeid) {
                                    scence = "S" + $scope.store_id + "";
                                }

                                if ($scope.id) {
                                    scence += "TBZF" + $scope.id;
                                }
                                $scope.path = $scope.path ? $scope.path : "pages/index/index";
                                $scope.scence = scence;
                                return $scope.getimg();
                            }

                            $scope.getimg = function() {
                                $scope.qrimage = "";
                                // 先存储scene，然后生成小程序码
                                if (!$scope.orderData) {
                                    helper.message("没有订单数据，无法存储", "error");
                                    return false;
                                } else {
                                    var value = {
                                        "order_id": $scope.id,
                                        "payment": Number($scope.orderData.payment),
                                        "body": "手工支付" + $scope.orderData.deliver_name,
                                        "kind": "taobao_pay"
                                    };
                                    dataService.tbSceneSave("TB" + $scope.id, value).then(function(result) {
                                        if (result.Msg == "ok") {
                                            $scope.getimgtwo();
                                        } else {
                                            helper.message("存储场景值失败，请联系客服解决", "error");
                                            return false;
                                        }
                                    });
                                }

                                // return $scope.getimgtwo();
                            }

                            $scope.getimgtwo = function() {
                                return dataService.acodeunlimitGet($scope.wxappid, $scope.scence, true, $scope.path).then(function(qrimage) {
                                    console.error("qrimage", qrimage);
                                    if (qrimage) {
                                        return $scope.qrimage = "data:image/png;base64," + qrimage;
                                    } else {
                                        helper.message("生成小程序码失败，请联系客服", "error");
                                        return false;
                                    }
                                });
                            }

                            $scope.show = function() {
                                $.alert({
                                    backdrop: 'static',
                                    keyboard: true,
                                    title: '<span>小程序二维码，请使用微信扫描</span>',
                                    body: $templateCache.get("views/directives.paymentqrcode.html"),
                                    // okBtn: '{{"ok" | translate}}',
                                    closeBtn: true,
                                    hasfoot: false,
                                    transition: true,
                                    width: 'small',
                                    // height: '200',
                                    show: function(e) {
                                        $compile($(e.currentTarget).contents())($scope);
                                        return true;
                                    },
                                    okHide: function(e) {},
                                });
                            }
                        }
                    ],
                    link: function(scope, element, attrs, ctrl) {}
                }
            }
        ])
})();